package com.example.tuling;

import java.util.*;

public class ListDifferenceFinder {

    public static void main(String[] args) {
        // 第一个字符串列表
        List<String> list1 = Arrays.asList(
            "1955234879459934208",
            "1955193244650946560",
            "1967968602721525760",
            "1955165971864469504",
            "1955312649166766080",
            "1968299890993569792",
            "1955225043720323072",
            "1956705496866742272",
            "1967535766416171008",
            "1967579762668380160",
            "1955189563930951680",
            "1955211268267032576",
            "1955351214411726848",
            "1955869446457769984",
            "1955170773469609984",
            "1955273143121985536",
            "1955544569750208512",
            "1955212745366814720",
            "1955289583539830784",
            "1955164282025525248",
            "1955303234439069696",
            "1958804969654452224",
            "1955175434033676288"
        );

        // 第二个字符串列表
        List<String> list2 = Arrays.asList(
            "1967774723569393664",
            "1955234879459934208",
            "1956257135303319552",
            "1955193244650946560",
            "1960386982159327232",
            "1955225043720323072",
            "1968244794263904256",
            "1957185419285356544",
            "1967579762668380160",
            "1955189563930951680",
            "1955211268267032576",
            "1955351214411726848",
            "1962812172391174144",
            "1955869446457769984",
            "1955273143121985536",
            "1956325500457836544",
            "1955164282025525248",
            "1967968602721525760",
            "1955312649166766080",
            "1968299890993569792",
            "1956705496866742272",
            "1955173547964219392",
            "1962858641714860032",
            "1955170773469609984",
            "1958804969654452224",
            "1955175434033676288"
        );

        // 调用方法获取差集
        List<String> difference = findDifference(list1, list2);

        // 打印结果
        System.out.println("第一个列表中独有的元素：");
        difference.forEach(System.out::println);
    }

    /**
     * 找出 list1 中存在但 list2 中不存在的元素
     */
    public static List<String> findDifference(List<String> list1, List<String> list2) {
        Set<String> set2 = new HashSet<>(list2); // 用 Set 加快查找速度
        List<String> result = new ArrayList<>();
        for (String s : list1) {
            if (!set2.contains(s)) {
                result.add(s);
            }
        }
        return result;
    }
}
